package com.shop.dingdongshoppingapi.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shop.dingdongshoppingapi.dto.LikeToCarDto;
import com.shop.dingdongshoppingapi.entity.Goods;
import com.shop.dingdongshoppingapi.entity.ShopCar;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;

public interface ShopCarDao extends BaseMapper<ShopCar> {
	/*获取goods商品总数量*/
	@Select("select count(*) from t_goods")
	int goodsLength();

	/*获取商品表随机四个商品的信息*/
	ArrayList<Goods> fourRandom(ArrayList<Integer> list);

	/*
	* 点击猜你喜欢,往购物车添加信息*/
	@Insert("insert into t_shopcar(uid, gname, gprice, gnum, gimage, gctime) values(#{uid},#{gname},#{gprice},#{gnum},#{gimg},now())")
	int addLikeToCar(LikeToCarDto likeToCarDto);

	/*
	* 点击增删数量按钮  改变  数据库商品数量*/
	@Update("update t_shopcar set gnum=#{gnum} where id=#{id}")
	int updateShopCarNum(@Param("gnum") Integer gnum, @Param("id") Integer id);

	/*
	* 如果已有此商品,进行数量+1*/
	@Update("update t_shopcar set gnum=gnum+1 where uid=#{uid} and gname=#{gname}")
	int addOneNum(@Param("uid") Integer token,@Param("gname") String gname);
}
